﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RayTracing
{
    public class PointLight : Light
    {
        P3 source;
        Color intensity;

        public PointLight(P3 source, Color intensity)  //Creates light from a certain point takes the point of origin and the intensity of the light 
        {                                              //works like a light bulb
            this.source = source;
            this.intensity = intensity;
        }

        #region Light Members

        public Color illumination(P3 point, SceneObject sceneObject) //Gives the illumination of the point light taking a P3 point and the sceneObject
        {
            P3 vector = P3.sub(source,point);
            float distance = P3.norm(vector);
            Color color = Color.scale(this.intensity, distance);

            P3 surfaceNormal = sceneObject.geometry.normal(point);
            float shade = P3.dot(surfaceNormal, vector);

            if (shade < 0 || Main.occluded(new Ray(point, this.source), sceneObject, distance))  // checks to see if the object is occluded(shadowed) or not.
            {                                                                                  // and how shaded it is. 
                return Color.BLACK;                                     // if occluded or is not hit by this light return Black.
            }
            else
            {
                return Color.scale(color, shade);             // if not in shadow and is hit by this light scale the color
            }
        }

        #endregion
    }
}
